<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Helptips extends MX_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model(array('admin_commoncall','admin_settings_model','admin_tips_model'));
		$this->load->library('pagination');
		//$this->admin_commoncall->check_admin_login();
		$this->template->set_theme('admin');
		$this->template->set_layout('default');
		//$this->template->set_partial('side_menu','layouts/side_menu');
		//$this->template->set_partial('nav_bar','layouts/nav_bar');

	}

	function index()
	{
		$status=1;
		
		if($this->input->post('filter')){
			$filter = $this->input->post('filter');
		
			switch ($filter) {
				case 'active':
					$status = 51;
					break;
				case 'inactive':
					$status = 1;
					break;
				case 'featured':
					$status = 51;
					$featured=true;
					break;
			}
		}
		

		$data['mode'] = "ADD";
		
		$data['help']['tips'] = $this->admin_tips_model->getTips($status = $status);
		
		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		//->set_partial('footer', 'footer/footer')
		->build('reports/helptips',$data);
	}

	function edit($id) {
	
		$data['mode'] = "EDIT";
		
		$data['tips']['info'] = $this->admin_tips_model->getTipsinfo($id);
		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		->build('reports/helptips', $data);
	}
	
	
	function submit()
	{
		
		$this->form_validation->set_rules('description','Description','xss_clean|required|max_length[250]');
		
		if ($this->form_validation->run() == true) {
			
			
			$data = array(
						
					'description' => $this->input->post('description'),
			);
			
			//var_dump($data);
			//die();
				
			$this->db->insert('tips',$data);
			$this->session->set_flashdata('message', 'Successfully!... ');
			redirect('secure/helptips');
			//$this->index();
			}else{
			$this->session->set_flashdata('message', 'Fields Can not be null!... ');
			$this->index();
			}
		
		
		
	}
	
	
	function update()
	{
	
		$this->form_validation->set_rules('description','Description','xss_clean|required|max_length[250]');
	
		if ($this->form_validation->run() == true) {
				
			$id = $this->input->post('id');
			
			$data = array(
	
					'id' => $id,
					'description' => $this->input->post('description'),
			);
			
			$this->db->where('id',$id);
			$this->db->update('tips',$data);
			$this->session->set_flashdata('message', 'Successfully!... ');
			redirect('secure/helptips/edit/'.$id);
		}else{
			$this->session->set_flashdata('message', 'Fields Can not be null!... ');
			$this->edit($id);
		}
	
	
	
	}
	
	
	
	
	function change_tips_status($status=NULL,$id=NULL){
		
		$this->admin_tips_model->change_tips_status($id,$status);
		redirect('secure/helptips/');
	}

	
	function delete($id)
	{
		$this->admin_tips_model->delete($id);
		$this->session->set_flashdata('msg', 'News Deleted...');
		redirect('secure/helptips');
	}
	
}